import { FreePromise } from "./promise";
export class Flow{
    constructor(){
        this.index=0;
        this.list=[]
        this.fp = new FreePromise()
    }
    append(func){
        var index = this.index
        var next = (rt)=>{
            if(this.list.length >index+1){
                this.list[index+1](rt)
            }else{
                this.fp.resolve(rt)
            }
            
        }
        
        var temp =  (arg)=>{
            func(next,arg)
        }
        this.list.push(temp)
        this.index +=1
    }
    run(arg){
        this.list[0](arg)
        return this.fp.promise
    }
}